const connection = require('../app/database')

class UserinfoService {
  // 获取用户信息
  async getInfoById(userId) {
    const statement = `select * from userinfo where user_id = ?;`
    const [result] = await connection.execute(statement, [userId])
    return result
  }
  // 修改用户昵称
  async rename(userId, newName) {
    const statement = `update userinfo set name = ? where user_id = ?`
    const result = await connection.execute(statement, [newName, userId])
    return result
  }
  // 编辑用户信息
  async editUserinfo(userId, age, gender, birthday, location) {
    const statement = `update userinfo set age = ?, gender = ?, birthday = ?, location = ? where user_id = ?;`
    const [result] = await connection.execute(statement, [age, gender, birthday, location, userId])
    return result
  }
  // 更新头像请求地址
  async updateAvatarUrlById(avatarUrl, userId) {
    const statement = `update userinfo set avatar_url = ? where user_id = ?`
    const [result] = await connection.execute(statement, [avatarUrl, userId])
    return result
  }
}

module.exports = new UserinfoService()